/*
 * @Author: DUST
 * @Date: 2023-05-26 15:29:57
 * @LastEditors: DUST
 * @LastEditTime: 2023-06-06 15:43:17
 * @FilePath: \koa-node-ts\app\model\User.ts
 * @Description:
 * undefined
 */

import { Model, Table, DataType, Column } from "sequelize-typescript";

@Table({
  tableName: "user", // 数据库表名称
  timestamps: true, // 自动维护时间
  freezeTableName: true, // 禁止修改表名，如果不写会把表名自动复数化，users
  paranoid: true, // 软删除
  indexes: [{ unique: true, fields: ['id', 'userId'] }]
})
export default class User extends Model<User> {
  @Column({
    type: DataType.INTEGER.UNSIGNED,
    autoIncrement: true,
    primaryKey: true,
    allowNull: false,
    comment: "用户id",
  })
  id!: number;

  @Column({
    type: new DataType.STRING(128),
    allowNull: false,
    comment: "用户唯一标识",
  })
  userId!: string;

  @Column({
    type: new DataType.STRING(128),
    comment: "昵称",
    validate: {
      len: [1, 128],
    },
  })
  nikname!: string;

  @Column({
    type: new DataType.STRING(128),
    allowNull: false,
    comment: "用户名",
    validate: {
      len: [1, 128],
      notNull: {
        msg: "用户名不能为空！",
      },
    },
  })
  name!: string;

  @Column({ comment: "用户手机号", type: new DataType.STRING(128) })
  phone!: string;

  @Column({ comment: "用户邮箱", type: new DataType.STRING(128) })
  email!: string;
}